package com.simple.utils;

import java.lang.reflect.Field;

import javax.servlet.http.HttpServletRequest;

/**
 * 填充form
 * @author 李凯
 * @version v-1.0
 * @date 2017-8-20
 * */
public class FullForm {
	
	public FullForm(){}
	
	/**
	 * 填充form
	 * @author 李凯
	 * @version v-1.0
	 * @date 2017-8-20
	 * @param formPath request
	 * @return ActionForm
	 * */
	public static ActionForm full(String formPath,HttpServletRequest request){
		ActionForm actionForm = null;
		try{
			Class<?> clazz = Class.forName(formPath);
			actionForm = (ActionForm)clazz.newInstance();
			Field[] fields = clazz.getDeclaredFields();
			for(Field field : fields){
				field.setAccessible(true);
				field.set(actionForm, request.getParameter(field.getName()));
				field.setAccessible(false);
			}
		}catch(Exception e){
			e.printStackTrace();
		}
		return actionForm;
	}
}
